Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
create-error-class
Advanced tools
The 'create-error-class' npm package is a utility that allows developers to create custom error classes in JavaScript. This is particularly useful for defining specific types of errors in applications, which can enhance error handling by making it easier to identify and react to different error conditions.
Creating custom error classes
This feature allows developers to create their own error classes. The custom error can then be thrown with a specific message, making it clear what type of error occurred.
const createError = require('create-error-class');
const MyCustomError = createError('MyCustomError');
throw new MyCustomError('Something went wrong');
Similar to 'create-error-class', 'http-errors' is used to create HTTP error objects. While 'create-error-class' is generic and can be used for any type of error, 'http-errors' is specifically tailored for HTTP errors, making it more suitable for web applications.
This package also allows the creation of custom error classes. It is quite similar to 'create-error-class' but offers additional options for setting default properties on the error instances, providing slightly more flexibility.
Create error class
$ npm install --save create-error-class
var createErrorClass = require('create-error-class');
var HTTPError = createErrorClass('HTTPError', function (props) {
this.message = 'Status code is ' + props.statusCode;
});
throw new HTTPError({statusCode: 404});
Return constructor of Errors with className
.
Required
Type: string
Class name of Error Object. Should contain characters from [0-9a-zA-Z_$]
range.
Type: function
Setup function, that will be called after each Error object is created from constructor with context of Error object.
By default setup
function sets this.message
as first argument:
var MyError = createErrorClass('MyError');
new MyError('Something gone wrong!').message; // => 'Something gone wrong!'
MIT © Vsevolod Strukchinsky
FAQs
Create Error classes
The npm package create-error-class receives a total of 2,018,791 weekly downloads. As such, create-error-class popularity was classified as popular.
We found that create-error-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.